package com.nineclock.attendance.controller;

import com.nineclock.api.attendance.AttendPunchControllerApi;
import com.nineclock.attendance.dto.AttendPunchDTO;
import com.nineclock.attendance.dto.AttendPunchUserWholeDayDTO;
import com.nineclock.attendance.service.AttendPunchService;
import com.nineclock.common.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@RestController
public class AttendPunchControllerApiImpl implements AttendPunchControllerApi {

    @Autowired
    AttendPunchService attendPunchService;

    @Override
    @PostMapping("/punch")
    public Result punch(@RequestBody AttendPunchDTO attendPunchDTO) {

        attendPunchService.punch(attendPunchDTO);

        return Result.success();
    }

    @Override
    @GetMapping("/get")
    public Result<AttendPunchUserWholeDayDTO> queryPunchRecord() {
        AttendPunchUserWholeDayDTO  wholeDayDTO = attendPunchService.queryPunchRecord();
        return Result.success(wholeDayDTO);
    }

    @Override
    @GetMapping("/members")
    public Result<List<AttendPunchDTO>> queryMembers(String startTime, String endTime) {
        List<AttendPunchDTO> attendPunchDTOList = attendPunchService.queryMembers(startTime, endTime);
        return Result.success(attendPunchDTOList);
    }

    @Override
    @GetMapping("/export")
    public void exportAttendData(String startTime, String endTime) throws IOException {
        attendPunchService.exportAttendData(startTime, endTime);

    }
}
